package com.baosight.sczx.zm.cd.service;
import java.util.HashMap;
import java.util.Map;
import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.StaticBlocks;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.zm.cd.domain.ZMCDDirLimtOrg; 

/**
 * <p>Title: ServiceZMCD14.java</p> 
 *</pre>
 */
public class ServiceZMCD14 extends ServiceEPBase { 
	@Override
	public EiInfo query(EiInfo inInfo) { 
		 
		String fdDirId = inInfo.getString("fdDirId");
		if(fdDirId!=null)
		{
			StaticTools.setQueryParameters(inInfo, "fdDirId", fdDirId, true);//添加查询条件
		} 
		EiInfo outInfo=inInfo;
		if(fdDirId!=null)
			outInfo = super.query(inInfo, "ZMCDDirLimtOrg.query", new ZMCDDirLimtOrg());
		else
			outInfo.addBlock("result").setBlockMeta(new ZMCDDirLimtOrg().eiMetadata);
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cd.department", "orgCode", "orgName", false));//部门
		outInfo.addBlock(StaticBlocks.GetLimit());
		EiBlock block = outInfo.addBlock("cmes.cd.department1");
		block.addMeta(new EiColumn("orgCode"));
		block.addMeta(new EiColumn("orgName"));
		Map<String,String> map = new HashMap<String,String>();
		map.put("fdDirId", inInfo.getCellStr(EiConstant.queryBlock, 0, "fdDirId"));
		block.addRows(dao.query("ZMCDDirLimtOrg.queryNotLimitOrg", map));
		outInfo.addBlock(CDBlocks.getDirBlock());
		
		return outInfo;
	}
	/**
	 * 删除  
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) {
		return super.delete(inInfo,"ZMCDDirLimtOrg.delete");
	}
	/**
	 * 新增 
	 */
	@Override
	public EiInfo insert(EiInfo inInfo) {
		
		EiInfo out=new EiInfo(); 
		ZMCDDirLimtOrg _dom = new ZMCDDirLimtOrg();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));   
			String keyId = TablePk.getInstance().getNextValue("T_CD_DIRLIMITORG");
			_dom.setFdKeyId(keyId); 
			this.dao.insert("ZMCDDirLimtOrg.insert",_dom);  
		}
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;   
	}

	/**
	 * 修改 
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {
		EiInfo out=new EiInfo(); 
		ZMCDDirLimtOrg _dom = new ZMCDDirLimtOrg();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));    
			this.dao.update("ZMCDDirLimtOrg.update",_dom);  
		}
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;   
	}
}
